package com.pm.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.enums.BusinessType;
import com.pm.business.domain.CompeteEnterpriseBadBehavior;
import com.pm.business.service.ICompeteEnterpriseBadBehaviorService;
import com.pm.common.utils.poi.ExcelUtil;
import com.pm.common.core.page.TableDataInfo;

/**
 * 不良行为Controller
 * 
 * @author zxl
 * @date 2022-05-07
 */
@RestController
@RequestMapping("/business/compete_bad_behavior")
public class CompeteEnterpriseBadBehaviorController extends BaseController
{
    @Autowired
    private ICompeteEnterpriseBadBehaviorService competeEnterpriseBadBehaviorService;

    /**
     * 查询不良行为列表
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompeteEnterpriseBadBehavior competeEnterpriseBadBehavior)
    {
        startPage();
        List<CompeteEnterpriseBadBehavior> list = competeEnterpriseBadBehaviorService.selectCompeteEnterpriseBadBehaviorList(competeEnterpriseBadBehavior);
        return getDataTable(list);
    }

    /**
     * 导出不良行为列表
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:export')")
    @Log(title = "不良行为", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompeteEnterpriseBadBehavior competeEnterpriseBadBehavior)
    {
        List<CompeteEnterpriseBadBehavior> list = competeEnterpriseBadBehaviorService.selectCompeteEnterpriseBadBehaviorList(competeEnterpriseBadBehavior);
        ExcelUtil<CompeteEnterpriseBadBehavior> util = new ExcelUtil<CompeteEnterpriseBadBehavior>(CompeteEnterpriseBadBehavior.class);
        util.exportExcel(response, list, "不良行为数据");
    }

    /**
     * 获取不良行为详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:query')")
    @GetMapping(value = "/{behaviorId}")
    public AjaxResult getInfo(@PathVariable("behaviorId") Long behaviorId)
    {
        return AjaxResult.success(competeEnterpriseBadBehaviorService.selectCompeteEnterpriseBadBehaviorByBehaviorId(behaviorId));
    }

    /**
     * 新增不良行为
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:add')")
    @Log(title = "不良行为", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompeteEnterpriseBadBehavior competeEnterpriseBadBehavior)
    {
        return toAjax(competeEnterpriseBadBehaviorService.insertCompeteEnterpriseBadBehavior(competeEnterpriseBadBehavior));
    }

    /**
     * 修改不良行为
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:edit')")
    @Log(title = "不良行为", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompeteEnterpriseBadBehavior competeEnterpriseBadBehavior)
    {
        return toAjax(competeEnterpriseBadBehaviorService.updateCompeteEnterpriseBadBehavior(competeEnterpriseBadBehavior));
    }

    /**
     * 删除不良行为
     */
    @PreAuthorize("@ss.hasPermi('business:compete_bad_behavior:remove')")
    @Log(title = "不良行为", businessType = BusinessType.DELETE)
	@DeleteMapping("/{behaviorIds}")
    public AjaxResult remove(@PathVariable Long[] behaviorIds)
    {
        return toAjax(competeEnterpriseBadBehaviorService.deleteCompeteEnterpriseBadBehaviorByBehaviorIds(behaviorIds));
    }
}
